package chen.web.forum;

import java.util.Date;

import org.codehaus.jackson.annotate.JsonIgnore;

import chen.web.BusinessException;
import chen.web.IdEntity;
import chen.web.favorite.Favoritable;
import chen.web.favorite.Favorite;
import chen.web.user.Account;

/**
 * @author song
 * 主题的某个回复
 */
public class Reply extends IdEntity implements Favoritable{
	
	private static final int Flag_Hide= 0x01;			//隐藏

	private Subject belongSubject;
	private Integer flag = 0;		//标记
	private String content;		//内容
	private Date date;			//发布时间
	private ForumAccount author;		//作者
	private String ip;
	private boolean fakeDelete;
	private boolean needChecking;
	
	protected Reply(){
		super(0);
	}
	
	public Reply(Subject belong){
		super(0);
		this.belongSubject = belong;
		if(belongSubject.isForbidReply()){
			throw new BusinessException(BusinessException.Forum_Forbid_Reply);
		}
	}
	
	void setId(int id) {
		this.id = id;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Date getDate() {
		return date;
	}
	void setDate(Date date) {
		this.date = date;
	}
	public ForumAccount getAuthor() {
		return author;
	}
	void setAuthor(ForumAccount author) {
		this.author = author;
	}
	@JsonIgnore 
	public Subject getBelongSubject() {
		return belongSubject;
	}
	void setBelongSubject(Subject belongSubject) {
		this.belongSubject = belongSubject;
	}
	
	public boolean isHide(){
		return (flag & Flag_Hide) == 1;
	}
	
	void setHide(boolean hide){
		if(hide)
			flag = flag | Flag_Hide;
		else 
			flag = flag & (~Flag_Hide);
	}
	
	void setFlag(Integer flag) {
		this.flag = flag;
	}

	Integer getFlag() {
		return flag;
	}
	void setIp(String ip) {
		this.ip = ip;
	}
	public String getIp() {
		return ip;
	}

	@Override
	public Favorite favor() {
		// TODO Auto-generated method stub
		Favorite favorite = new Favorite(this);
		favorite.setTitle("回复:"+this.getBelongSubject().getTitle());
		favorite.setDescription("fsdafsdfdas");
		return favorite;
	}
	
	void setNeedChecking(boolean needChecking) {
		this.needChecking = needChecking;
	}

	public boolean isNeedChecking() {
		return needChecking;
	}

	void setFakeDelete(boolean fakeDelete) {
		this.fakeDelete = fakeDelete;
	}

	public boolean isFakeDelete() {
		return fakeDelete;
	}
}
